layui.use(['layer','form','table','element','upload'],function () {
    var layer = layui.layer
        ,form = layui.form
        ,table =layui.table
        ,upload = layui.upload
        ,element = layui.element;

    //文件上传
    var uploadInst = upload.render({
        elem: '#upload' //绑定元素
        ,url: '/system/siteMapUpload' //上传接口
        ,exts:'xml'
        ,size:"10000"
        ,done: function(res){
            //上传完毕回调
            layer.msg("上传成功");
        }
        ,error: function(){
            //请求异常回调
            layer.msg("系统错误，上传失败！")
        }
    });

    $("#siteMapDesc").bind("click",function () {

        $.ajax({
            type:"POST"
            ,url:"/system/sitemappath"
            ,success:function (res) {
                window.open(res.data.path,"_black");
            }
            ,error:function () {
                layer.msg("服务器错误！");
            }
        });

    })


    function rightMenu(){

        $(".layui-tab-title li",window.parent.document).on("contextmenu",function (e) {
            var rightmenu = $(".rightmenu",window.parent.document);
            rightmenu.find("li").attr('data-id',$(this).attr("lay-id"));
            l = e.clientX;
            t = e.clientY;
            rightmenu.css({ left:l, top:t}).show();
            return false;
        });
        //左键点击隐藏
        $("body,.layui-tab-title li",window.parent.document).click(function(){
            $(".rightmenu").hide();
        });

    }

    function iframeWH(){
        var H = $(window).height();
        $("iframe",window.parent.document).css("height",H+"px");
    }
     
     //搜索
    $("#search").on("click",function () {
        table.reload("data",{
            page:{
                curr:1
            }
            ,where:{
                source:$("#source").val(),
            }
        })
    });

    $("#run").on("click",function () {
        $.ajax({
            type:"POST"
            ,url:"/admin/spider/run"
            ,success:function (res) {
                layer.msg(res.message);
                table.reload("data",{
                    page:{
                        curr:1
                    }
                })
            }
            ,error:function () {
                layer.msg("服务器错误！");
            }
        });
    })



});
